package cc.atliberty.oa.controller;

import cc.atliberty.oa.pojo.Dept;
import cc.atliberty.oa.service.DeptService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/dept/modify")
public class ModifyDeptServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        String deptno = request.getParameter("deptno");
        String dname = request.getParameter("dname");
        String loc = request.getParameter("loc");
        Dept dept = new Dept(deptno,dname,loc);
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        DeptService deptService = context.getBean("deptService", DeptService.class);
        deptService.modifyDept(dept);
        response.sendRedirect(request.getContextPath() + "/dept/list");
    }
}
